package com.admission.web.admin;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.admission.model.SchoolIntr;
import com.admission.service.SchoolIntrManager;
import com.admission.web.CrudActionSupport;

@Namespace("/admin")
public class SchoolIntrAdminAction extends CrudActionSupport<SchoolIntr> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2097523970526106467L;
	
	private SchoolIntr entity;
	private String type;
	private SchoolIntrManager schoolIntrManager;

	public SchoolIntr getModel() {
		return entity;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String input() throws Exception {
		return INPUT;
	}

	@Override
	public String save() throws Exception {
		try{
			schoolIntrManager.save(entity);
			 this.addActionMessage("操作成功");
		} catch (Exception e) {
		   this.addActionMessage("操作失败，请重新操作");
	    }
		return INPUT;
	}

	@Override
	public String delete() throws Exception {
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if(StringUtils.isEmpty(type)){
			entity = new SchoolIntr();
		}else{
			entity = schoolIntrManager.getByType(type);
		}
		
	}

	public SchoolIntr getEntity() {
		return entity;
	}

	public void setEntity(SchoolIntr entity) {
		this.entity = entity;
	}

	@Autowired
	public void setSchoolIntrManager(SchoolIntrManager schoolIntrManager) {
		this.schoolIntrManager = schoolIntrManager;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

}
